import request from "@/utils/request";
import type { AxiosPromise } from "axios";
import type { AlipayRegisterData, AlipayLoginData, AlipayLoginResponse } from "./types";
import { useUserStore } from "@/stores/modules/user";
import { vueMetaEnv } from "@/settings";

class AlipyApi {
  // 静默登录公众号.
  login(data: AlipayLoginData): AxiosPromise<AlipayLoginResponse> {
    data.tenant = useUserStore().user.tenant;
    data.appId = vueMetaEnv.APP_ALIPAY_APPID;
    return request({
      url: "/v1/front/rbac/ali/auth",
      method: "post",
      data,
      headers: {
        Authorization: false
      }
    });
  }

  // 阿里用户注册登录.
  register(data: AlipayRegisterData): AxiosPromise<AlipayLoginResponse> {
    data.tenant = useUserStore().user.tenant;
    data.appId = vueMetaEnv.APP_ALIPAY_APPID;
    return request({
      url: "/v1/front/rbac/ali/register",
      method: "post",
      data,
      headers: {
        Authorization: false
      }
    });
  }
}

const alipayApi = new AlipyApi();
export { alipayApi };
